import api from '@/common/request/index.js'
import tools from '@/common/utils/tools.js'
const state = {
	order: [],
	info_box: {},
	game: [] ,      // 获取游戏
	info: {},       // 登录基础信息
	key: null,		// 共享积分返回的信息
	points: 0,		// 最大可共享积分
	shareDetail: null,
	shareType: false, // 分享状态
}
// 同步
const mutations = {
    set_game(state, payload) {
        state.game= payload
    },
    set_info(state, payload) {
        state.info= payload
    },
    set_info_id(state, payload) {
        state.info.member_id = payload
    },
	
	set_share_score(state,payload) {
		state.key = payload
	},
	
	set_points(state,payload) {
		state.points = payload
	},
	set_shareInfo(state,payload) {
		payload.create_time = tools.time_data(payload.create_time, 'g_data');
		state.shareDetail = payload
	},
	set_shareType(state,payload) {
		payload.create_time = tools.time_data(payload.create_time, 'g_data');
		state.shareType = payload
	}
}
// 异步
const actions = {
  get_game({commit}, payload) {
  	commit('set_game', payload)
  },
  get_shareInfo({commit}, payload) {
  	commit('set_shareInfo', payload)
  },
  get_shareType({commit}, payload) {
  	commit('set_shareType', payload)
  },
  get_info({commit}, payload) {
  	commit('set_info', payload)
  },
  get_info_id({commit}, payload) {
    commit('set_info_id', payload)
  },
  
  //共享积分
  get_share_score ({commit,state},payload) {
	  
	  return new Promise((resolve, reject) => {
		  api ('shareScore', payload).then(res => {
			  commit('set_share_score', res.data)
			  resolve(res)
		  }).catch(e => {
			  reject(e)
		  })
	  })
  },
  
  //获取当前可共享的积分
  get_points({commit}, payload) {
	  return new Promise((resolve, reject) => {
		  api ('getPoints', payload).then(res => {
			  commit('set_points', res.data)
			  resolve(res)
			  
		  }).catch(e => {
			  
			  reject(e)
			})
	  })
  },
  //领取积分
  get_receive_points({commot},payload) {
	  
	  return new Promise((resolve, reject) => {
		  api('receiveSharePoints', payload).then (res => {
			  
			  resolve(res)
		  }).catch(e => {
			  reject(e)
		  })
	  })
  }
}



export default {
    namespaced: true,
    state,
    mutations,
    actions
}